package com.seecen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seecen.pojo.entity.Type;
import com.seecen.service.TypeService;
import com.seecen.mapper.TypeMapper;
import com.seecen.utils.Result;
import com.seecen.utils.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WQL
 * @description 针对表【hm_company_type】的数据库操作Service实现
 * @createDate 2025-10-16
 */
@Slf4j
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    /**
     * 获取所有有效的主分类（未删除）
     * 对应前端：getMainTabs()
     * @return Result<List<Type>>
     */
    @Override
    public Result getAllType() {
        try {
            List<Type> typeList = typeMapper.selectAll();

            // 判断是否查询到数据
            if (typeList == null || typeList.isEmpty()) {
                log.warn("查询分类列表：未找到任何有效数据");
                return Result.build(null, ResultCode.DATA_NOT_FOUND);
            }

            log.info("查询到 {} 条分类数据", typeList.size());
            return Result.ok(typeList);

        } catch (Exception e) {
            log.error("查询分类列表时发生异常", e);
            return Result.build(null, ResultCode.DATA_NOT_FOUND);
        }
    }
}